/*=============================================================================
*
*   Copyright (C) 2020 All rights reserved.
*
*   Filename:		time_phase.hpp
*
*   Author: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Date: 2020-02-21 03:52
*
*   Last Editors: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Last modified:	2020-02-28 03:41
*
*   Description:
*
=============================================================================*/
#ifndef TIMEPHASE_H
#define TIMEPHASE_H

#include "../util/indexed.hpp"
#include "time_period_interface.hpp"
#include <boost/property_tree/ptree.hpp>

namespace geoxfem {
namespace model {

struct TimePhase : util::Indexed, ITimePeriod {
  using ptree = boost::property_tree::ptree;

  TimePhase(const _real& start, const _real& during, const ptree& data)
                        : util::Indexed{data.get<int>("id")},
                          ITimePeriod{start, during},
                          m_data{data} {}
  TimePhase()                 = default;
  ~TimePhase()                = default;
  TimePhase(const TimePhase&) = default;
  TimePhase(TimePhase&&)      = default;
  TimePhase& operator=(const TimePhase&) = default;
  TimePhase& operator=(TimePhase&&) = default;

  /**
   * @brief getData
   *
   * @return
   */
  ptree getData() const {
    return m_data;
  }

  /**
   * @brief getDeltaTime
   *
   * @return
   */
  _real getDeltaTime() const {
    return m_data.get<_real>("delta_time");
  }

  /**
   * @brief operator<<
   *
   * @param os
   * @param phase
   *
   * @return
   */
  friend std::ostream& operator<<(std::ostream& os, const TimePhase& phase) {
    os << "Phase #" << phase.getIndex() << "("
       << std::to_string(phase.getStartTime()) << "--"
       << std::to_string(phase.getEndTime()) << ':' << phase.getDeltaTime()
       << ')';
    return os;
  }

private:
  ptree m_data;
};

}  // namespace model
}  // namespace geoxfem

#endif /* TIMEPHASE_H */
